const app = getApp();
import util from '../../utils/index.js';
Component({
  /**
   * 组件的一些选项
   */
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的对外属性
   */
  properties: {
    bgColor: {
      type: String,
      default: ''
    },
    isCustom: {
      type: [Boolean, String],
      default: false
    },
    isBack: {
      type: [Boolean, String],
      default: false
    },
    bgImage: {
      type: String,
      default: ''
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom
  },
  /**
   * 组件的方法列表
   */
  methods: {

    BackPage() {
      util.navigateBack({
        delta: 1
      });
    },
    toHome() {
      util.reLaunch({
        url: '/pages/index/index',
      })
    }
  },
  lifetimes: {
    attached() {
      this.data.CustomBar = app.globalData.CustomBar
      if(!this.data.CustomBar || this.data.CustomBar==NaN || this.data.CustomBar<0){
        let custom = util.getMenuButtonBoundingClientRect();
        if(Object.keys(custom).length==0){
          app.globalData.CustomBar = 48 + this.data.StatusBar;  
          this.setData({
            CustomBar: app.globalData.CustomBar,
          })
          return false
        }
        let timer = setInterval(()=>{
          if(custom.bottom){
            clearInterval(timer)
            timer = null
            app.globalData.CustomBar = custom.bottom + custom.top - this.data.StatusBar;
            this.setData({
              CustomBar: app.globalData.CustomBar,
            })
          }
        })
      }else{
        this.setData({
          CustomBar: app.globalData.CustomBar
        })
      }
     
    }
  }
})